﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace com.weijie.tools2.Forms
{
    public partial class FormCharts : Form
    {
        public FormCharts()
        {
            InitializeComponent();

            this.DoubleBuffered = true;  //激活双缓冲, 以防止拖动的时候窗体闪烁
        }

        private void FormCharts_Load(object sender, EventArgs e)
        {

        } 

        private void Form1_Resize(object sender, EventArgs e)
        {
            //if(this.WindowState == FormWindowState.Maximized)
            //{
            //    ResponsiveEnd();
            //}

            ResponsiveEnd();
        }

        private void FormCharts_ResizeEnd(object sender, EventArgs e)
        {
            ResponsiveEnd();
        }


        //Maximize & Restore "Event"
        const int WM_SYSCOMMAND = 0x0112;
        const int SC_MAXIMIZE = 0xF030;
        const int SC_RESTORE = 0xF120;
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == WM_SYSCOMMAND)
            {
                if (m.WParam == (IntPtr)SC_MAXIMIZE || m.WParam == (IntPtr)SC_RESTORE)
                    this.OnResizeEnd(EventArgs.Empty);
            }
        }


        //这个方法的作用是当窗体大小改变时，重新计算控件的位置和大小
        // 让第二行的第二列的宽度加大一点, 让左边不会显得太空荡
        // 这里需要根据设置来重新计算
        private void ResponsiveEnd()
        { 
            if (this.Width <= 450)
            {
                tableLayoutPanel2.ColumnStyles[1].Width = 350;
            }
            else if (this.Width < 1351) // 这里其实对像现在的写法这种嵌入的窗体, 还得重新计算, 嵌入的会把窗体给最大化
            {
                tableLayoutPanel2.ColumnStyles[1].Width = tableLayoutPanel2.Width - (chart1.Width + chart1.Margin.Right);
            }
            else
            {
                tableLayoutPanel2.ColumnStyles[1].Width = tableLayoutPanel2.Width -
                    (chart1.Width + chart2.Width + chart1.Margin.Right + chart2.Margin.Right);
            }
            if (this.Height <= 775)
            {
                panel8.Height = 290;
            }
            else
            {
                panel8.Height = panel7.Height;
            }
        }
    }
}
